package com.shaw.workrecord.controller;

import com.shaw.workrecord.entity.PageResponse;
import com.shaw.workrecord.entity.ResponseBean;
import com.shaw.workrecord.pojo.request.*;
import com.shaw.workrecord.pojo.response.ChildrenResponse;
import com.shaw.workrecord.pojo.response.RecordResponse;
import com.shaw.workrecord.service.IChildrenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jiangjunhui
 * @description 孩子相关接口
 * @date 2023/8/9 17:46
 */
@Api(tags = {"孩子相关接口"})
@RestController
@Validated
public class ChildrenController {

    @Autowired
    private IChildrenService service;

    @ApiOperation(value = "孩子列表", notes = "", httpMethod = "GET")
    @GetMapping("/children")
    public ResponseBean<List<ChildrenResponse>> getList() {
        return ResponseBean.success(service.getChildrenList());
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ChildrenAddRequest", name = "request", value = "", required = true)
    })
    @ApiOperation(value = "新增孩子", notes = "", httpMethod = "POST")
    @PostMapping("/children")
    public ResponseBean<Boolean> addRecord(@RequestBody ChildrenAddRequest request) {
        if (service.addChildren(request)) {
            return ResponseBean.success(true);
        }
        return ResponseBean.failure("新增失败");
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ChildrenEditRequest", name = "request", value = "", required = true)
    })
    @ApiOperation(value = "编辑孩子", notes = "", httpMethod = "PUT")
    @PutMapping("/children")
    public ResponseBean<Boolean> editRecord(@RequestBody ChildrenEditRequest request) {
        if (service.editChildren(request)) {
            return ResponseBean.success(true);
        }
        return ResponseBean.failure("编辑失败");
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "long", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "删除孩子", notes = "", httpMethod = "DELETE")
    @DeleteMapping("/children/{id}")
    public ResponseBean<Boolean> deleteRecord(@PathVariable("id") Long id) {
        if (service.removeChildren(id)) {
            return ResponseBean.success(true);
        }
        return ResponseBean.failure("删除失败");
    }
}
